<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('导航列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="card card-primary card-outline card-outline-tabs mt-2 mb-0">
        <div class="card-header p-0 border-bottom-0">
            <ul class="nav nav-tabs">
                <li class="nav-item">
                    <a href="/navigate/list.html" class="nav-link" th:classappend="${modeType == ''?'active':''}">所有导航</a>
                </li>
                <li class="nav-item">
                    <a href="/navigate/list.html?modeType=friend" class="nav-link" th:classappend="${modeType == 'friend'?'active':''}">友情链接</a>
                </li>
                <li class="nav-item">
                    <a href="/navigate/list.html?modeType=tab" class="nav-link" th:classappend="${modeType == 'tab'?'active':''}">底部导航</a>
                </li>
                <li class="nav-item" >
                    <a href="/navigate/list.html?modeType=footer" class="nav-link" th:classappend="${modeType == 'footer'?'active':''}">手机导航</a>
                </li>
            </ul>
        </div>
        <div class="card-body">
            <table id="bootstrap-table" class="table-striped"></table>
        </div>
    </div>
    <div class="toolbar" id="toolbar" role="group">
        <a class="btn btn-success" onclick="navigateAdd()">
            <i class="fa fa-plus"></i> 添加
        </a>
    </div>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var newpageDatas = [[${@dict.getType('qdx_navigate_newpage')}]];
    var statusDatas = [[${@dict.getType('qdx_state_type')}]];
    var prefix = "/navigate";

    var modeType = [[${modeType}]];

    $(function() {
        var options = {
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            url: prefix + "/list.json",
            queryParams: queryParams,
            createUrl: prefix + "/add.html",
            updateUrl: prefix + "/edit.html?id={id}",
            removeUrl: prefix + "/remove.json",
            modalName: "导航",
            columns: [
                {
                    field: 'id',
                    title: 'id'
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'url',
                    title: '跳转地址'
                },
                {
                    field: 'newPage',
                    align: 'center',
                    title: '新页面打开',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(newpageDatas, value);
                    }
                },
                {
                    field: 'sort',
                    align: 'center',
                    title: '排序'
                },
                {
                    field: 'status',
                    title: '是否启用',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statuTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.modeType = modeType;
        return search;
    }

    //禁用或启用
    function statuTools(row) {
        if (row.status === 0) {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="FrozenOrThaw(\'' + row.id + '\',\'' +1+ '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="FrozenOrThaw(\'' + row.id + '\',\'' +0+ '\')"></i> ';
        }
    }

    //禁用或启用操作
    function FrozenOrThaw(id,sta) {
        table.set();
        var str = "";
        if (sta === "0") {
            str = "确定要启用该导航吗？"
        } else {
            str = "确定要禁用该导航吗？"
        }
        $.modal.confirm(str, function () {
            var data = {"id": id, "status": sta};
            $.operate.submit(prefix + "/status.json", "post", "json", data);
        });
    }

    //添加
    function navigateAdd() {
        $.modal.open("添加导航", prefix + "/add.html?modeType=" + modeType);
    }
</script>
</body>
</html>